package test19.file;

import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;

public class FileCreate {
    public static void main(String[] args) {
    }

    //文件创建的三种方式
    //第一种
    @Test
    public void create(){
        String filePath = "D:\\news1.txt";
        File file = new File(filePath);
        try {
            file.createNewFile();
            System.out.println("文件创建成功");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    //第二种
    @Test
    public void create1(){
        File parentFile = new File("d:\\");
        String fileName = "new2.txt";
        File file = new File(parentFile, fileName);
        try {
            file.createNewFile();
            System.out.println("文件创建成功");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    //第三种
    @Test
    public void create2(){
        String parentFile = "d:\\";
        String fileName = "news3.txt";
        File file = new File(parentFile,fileName);
        try {
            file.createNewFile();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

